$(function () {
    var channel = getQueryString("channel");
    $(".back-wrapper").click(function () {
        location.href = "./mine.html?channel="+channel;
    });
    $(".home-wrapper").click(function () {
        location.href = "../index.html?channel="+channel;
    });
});

function getCode() {
    var phone = $(".phone-wrapper .phone").val();
    if(phone == "" || phone.length != 11){
        Toast("请将手机号填写完整");
    }else{
        $.ajax({
            type:'get',
            url:BASE_URl + "user/sms/send?mobile="+phone,
            success:function (data) {
                if(data.success){
                    Toast("已发送验证码至手机号");
                    $(".get-code").hide().siblings(".sended").css("display","inline-block");
                    countDown();
                }else{
                    Toast("发送失败，请联系客服");
                }
            }
        });
    }
}

function countDown() {
    var sec = parseInt($(".sended span").html());
    var timer = setInterval(function () {
        sec --;
        $(".sended span").html(sec);
        if(sec < 10){
            $(".sended span").html("0" + sec);
        }
        if(sec == 0){
            clearInterval(timer);
            $(".sended").hide().siblings(".get-code").css("display","inline-block");
        }
    },1000);
}

function submitCode() {
    var phone = $(".phone-wrapper .phone").val();
    var code = $(".code-wrapper .code").val();
    if(phone == "" || code == ""){
        Toast("请填写完整信息");
    }else{
        $.ajax({
            type:'get',
            url:BASE_URl + "user/bind/tel?mobile=" + phone + "&code=" + code,
            success:function (data) {
                if(data.success){
                    Toast("绑定成功");
                    setTimeout(function () {
                        location.href = "./mine.html?channel="+getQueryString("channel");
                    },1000);
                }else{
                    Toast("绑定失败，请重试");
                }
            }
        });
    }
}